<?php
include_once("header.php");
?>
<script src="resource/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#btn_add").click(function() {
            var name = $("#student_name").val();
            var age =  $("#student_age").val();
            var tel =  $("#student_tel").val();
            if($.trim(name)==''){
                alert("请输入姓名！");
            }
            else if($.trim(age)==''){
                alert("请输入年龄！");
            }
            else if($.trim(tel)==''){
                alert("请输入电话号码！");
            }
            else {
                var form_data = {
                    name: name,
                    age: age,
                    tel: tel
                };
                /*或者如下写法：
                var form_data = {};
                form_data.name = name;
                form_data.age = age;
                form_data.tel = tel;
                */
                $.ajax({
                    type: "POST",
                    url: 'add_submit.php',
                    data: form_data,
                    success: function (response) {
                        if (response == 'success')
                            window.location.href = 'index.php';
                        //else
                    }
                });
            }
            return false;
        });
    });
</script>

<div class="container body-content">
<h2>Create</h2>
<div class="form-horizontal">
    <h4></h4>
    <hr />
    <form id="form1" name="form1" method="post">
        <div class="form-group">
            <label class="control-label col-md-2">Name</label>
            <div class="col-md-10">
                <input class="form-control text-box single-line" id="student_name" name="student_name" type="text"  title=""/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">Age</label>
            <div class="col-md-10">
                <input class="form-control text-box single-line" id="student_age" name="student_age" type="text"  title=""/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">Tel</label>
            <div class="col-md-10">
                <input class="form-control text-box single-line" id="student_tel" name="student_tel" type="text" title=""/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" id="btn_add" name="btn_add" value="Create" class="btn btn-default" />&nbsp;&nbsp;&nbsp;
                <a class="btn btn-default" href="index.php">Return</a>
            </div>
        </div>
    </form>
</div>
</div>